package com.jwthhealth_pub.old.sportfitness.view.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.sportfitness.module.SprotCourseInfoModule;
import com.jwthhealth_pub.old.sportfitness.view.SportCourseListActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/1/6.
 */
public class SportItemBodyAdatper extends RecyclerView.Adapter {

    SportCourseListActivity activity;
    SprotCourseInfoModule.DataBean.VideoListBean data;
    List<SprotCourseInfoModule.DataBean.VideoListBean.MainDescBean> list;

    public SportItemBodyAdatper(SportCourseListActivity sportCourseListActivity, SprotCourseInfoModule.DataBean.VideoListBean videoListBean) {
        this.activity = sportCourseListActivity;
        this.data = videoListBean;
        list = videoListBean.getMain_desc();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(activity, R.layout.item_sport_course_info_describe, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        SprotCourseInfoModule.DataBean.VideoListBean.MainDescBean descBean = list.get(position);
        viewHolder.title.setText(descBean.getName());
        viewHolder.rv.setLayoutManager(new LinearLayoutManager(activity));
        viewHolder.rv.setAdapter(new InnerAdatper(activity, descBean.getDesc()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        private TextView title;
        private RecyclerView rv;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.head_title);
            rv = (RecyclerView) itemView.findViewById(R.id.body_item_rv);
        }
    }

    private class InnerAdatper extends RecyclerView.Adapter {

        List<String> list;
        SportCourseListActivity mAcitivty;

        public InnerAdatper(SportCourseListActivity acitivty, List<String> desc) {
            this.mAcitivty = acitivty;
            list = desc;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = View.inflate(mAcitivty, R.layout.item_sport_temp_inner, null);
            return new ViewHolder(view);
        }


        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            String s = list.get(position);
            ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.text.setText(s);
        }

        @Override
        public int getItemCount() {
            return list.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder{

            TextView text;

            public ViewHolder(View itemView) {
                super(itemView);
                text = (TextView) itemView.findViewById(R.id.text);
            }
        }
    }
}
